package com.example.jdbcdemo.controller;

import com.example.jdbcdemo.mapper.CustomerMapper;
import com.example.jdbcdemo.pojo.Customer;
import com.example.jdbcdemo.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerMapper customerMapper;

    //返回所有客户信息
    @PostMapping("/queryCustomerList")
    public Result<List<Customer>> queryCustomerList(){
        List<Customer> customerList=customerMapper.queryCustomerList();
        return Result.success(customerList);
    }
    //新增客户
    @PostMapping("/add")
    public Result addCustomer(@RequestBody Customer customer){
        customerMapper.addCustomer(customer);
        return Result.success();
    }
    //通过id删除对应客户
    @PostMapping("/deletecustomer")
    public Result deleteCustomer(@RequestBody Customer customer){
        customerMapper.deleteCustomer(customer.getId());
        return Result.success();
    }
    //修改对应id的客户信息
    @PostMapping("/updatecustomer")
    public Result updateCustomer(@RequestBody Customer customer){
        customerMapper.updateCustomerById(customer);
        return Result.success();
    }
}
